package com.eatme.core.set;

import com.eatme.core.LinkedList;

import java.util.ArrayList;
import java.util.Random;

// 无序集合
public class LinkedListSet<E> implements Set<E> {

    private LinkedList<E> list;

    public LinkedListSet() {
        list = new LinkedList<>();
    }

    @Override
    public void add(E e) {
        if (!list.contains(e))
            list.addFirst(e);
    }

    @Override
    public void remove(E e) {
        list.removeElement(e);
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 1000; i++) {
            arrayList.add(random.nextInt(1000));
        }
        System.out.println("arraylist size:"+arrayList.size());
        LinkedListSet<Integer> set = new LinkedListSet<>();
        for (Integer num: arrayList)
            set.add(num);
        System.out.println("bstSet size:"+set.getSize());
    }
}
